package com.ybkj.o2o.sales.entity;


import com.ybkj.o2o.sales.common.DateTimeSerialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 优惠劵规则.
 * 
 * @author Shine
 * 
 */
public class CouponRule extends Base {
  
  private static final long serialVersionUID = 1L;

  public static final int COUPONRULE_STATUS_NOTSTART = 0;// 未开始

  public static final int COUPONRULE_STATUS_ONUSING = 1;// 使用中

  public static final int COUPONRULE_STATUS_OVERDUE = 2;// 已过期

  public static final int TYPE_DISCOUNT = 0;

  public static final int TYPE_DEDUCTION = 1;

  private String title;// 优惠券简介

  private String code;// 编码

  private Date start;// 开始时间

  private Date end;// 结束时间

  private Long companyId;

  private boolean lapsed;// 是否失效

  private List<Coupon> coupons;

  private Integer type;// 优惠券类型 0打折 1抵扣

  private CouponType couponType;// 服务类型

  private Double discount;// 打折优惠券

  private BigDecimal money;// 抵扣优惠券

  private Integer number;// 优惠券数量

  private Integer eachLimit;// 每人限领：0为不限制

  private String appKey;
  
  private Long couponTypeId;//服务类型id(couponType为跑腿则是跑腿类型id)

  public void setCouponType(CouponType couponType) {
    this.couponType = couponType;
  }

  public CouponType getCouponType() {
    return couponType;
  }


  public Integer getType() {
    return type;
  }

  public void setType(Integer type) {
    this.type = type;
  }

  public String getAppKey() {
    return appKey;
  }

  public void setAppKey(String appKey) {
    this.appKey = appKey == null ? null : appKey.trim();
  }

  public Long getCouponTypeId() {
    return couponTypeId;
  }

  public void setCouponTypeId(Long couponTypeId) {
    this.couponTypeId = couponTypeId;
  }

  public Double getDiscount() {
    return discount;
  }

  public void setDiscount(Double discount) {
    this.discount = discount;
  }

  public BigDecimal getMoney() {
    return money;
  }

  public void setMoney(BigDecimal money) {
    this.money = money;
  }

  public Integer getNumber() {
    return number;
  }

  public void setNumber(Integer number) {
    this.number = number;
  }

  public Integer getEachLimit() {
    return eachLimit;
  }

  public void setEachLimit(Integer eachLimit) {
    this.eachLimit = eachLimit;
  }

  public String getTitle() {
    return title;
  }

  public void setTitle(String title) {
    this.title = title;
  }

  public String getCode() {
    return code;
  }

  public void setCode(String code) {
    this.code = code;
  }

  @JsonSerialize(using = DateTimeSerialize.class)
  public Date getStart() {
    return start;
  }

  public void setStart(Date start) {
    this.start = start;
  }

  @JsonSerialize(using = DateTimeSerialize.class)
  public Date getEnd() {
    return end;
  }

  public void setEnd(Date end) {
    this.end = end;
  }

  public boolean isLapsed() {
    return lapsed;
  }

  public void setLapsed(boolean lapsed) {
    this.lapsed = lapsed;
  }

  public List<Coupon> getCoupons() {
    return coupons;
  }

  public void setCoupons(List<Coupon> coupons) {
    this.coupons = coupons;
  }

  /**
   * 获取状态.
   */
  public Integer getTimeStatus() {
    if (start.getTime() > new Date().getTime()) {
      return COUPONRULE_STATUS_NOTSTART;
    } else if (null != end && end.getTime() < new Date().getTime()) {
      return COUPONRULE_STATUS_OVERDUE;
    } else {
      return COUPONRULE_STATUS_ONUSING;
    }
  }

  public Long getCompanyId() {
    return companyId;
  }

  public void setCompanyId(Long companyId) {
    this.companyId = companyId;
  }


  public enum CouponType {
    /**
     * 代驾.
     */
    daijia,
    /**
     * 专车.
     */
    zhuanche,
    /**
     * 跑腿.
     */
    paotui,
    /**
     * 货运.
     */
    freight,
    /**
     * 洗车.
     */
    xiche,
    /**
     * 拼车.
     */
    pinche,
    /**
     * 专线.
     */
    zhuanxian,
    /**
     * 加油站.
     */
    gasstation,
    /**
     * 全部.
     */
    all

  }

}
